<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: view.html.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');

/**
 *
 */
class JoomgpstracksViewTracks extends JView {
    /**
     *
     * @global object $mainframe
     * @global string $option
     * @param object $tpl
     */
    function display($tpl = null) {
        global $mainframe, $option;

        if($this->getLayout() == 'form'):
            $this->_displayForm($tpl);
            return;
        endif;

        $model =& $this->getModel();

        $order = JRequest::getVar( 'order', 'order', 'post', 'string' );

        $filter_order		= $mainframe->getUserStateFromRequest( "$option.filter_order",		'filter_order',		'ordering',	'cmd' );
        $filter_order_Dir	= $mainframe->getUserStateFromRequest( "$option.filter_order_Dir",	'filter_order_Dir',	'',			'word' );
		$search				= $mainframe->getUserStateFromRequest( "$option.search",			'search',			'',		'string' );
		$search				= JString::strtolower( $search );

        $lists['order']		= $filter_order;
        $lists['order_Dir']	= $filter_order_Dir;
        $lists['search']= $search;

		$rows =& $this->get( 'Data');
		$total		= & $this->get( 'Total');
        $pagination = & $this->get( 'Pagination' );

        $this->assignRef('lists',	$lists);
        $this->assignRef( 'rows',   $rows);
        $this->assignRef('pagination',	$pagination);

        parent::display($tpl);
    }

    function _displayForm($tpl)  {

        JHTML::script('jquery.js', 'components/com_joomgpstracks/assets/js/', false);
        JHTML::script('multifile.js', 'components/com_joomgpstracks/assets/js/', false);
        $cid =& JRequest::getVar( 'cid', array(), 'post', 'array' );
        $id = implode(',', $cid);
        
        $editor =& JFactory::getEditor();
        $model = $this->getModel();
        $rows = $model->getCats();
        $cats = $model->createCatList($rows);
        $terrain = $model->getTerrain();
        $track = $model->getTrack($id);
        $users = array(
            array('id' => 0, 'text' => JText::_('GPS_PUPLIC')),
            array('id' => 1, 'text' => JText::_('GPS_REGISTERED'))
        );

        $lists['cats'] 	= JHTML::_('select.genericlist',   $cats, 'catid', 'size="1"', 'id', 'title', $track->catid );
        $lists['terrain'] = JHTML::_('select.genericlist',   $terrain, 'terrain[]', 'multiple="multiple" size="5"', 'title', 'title', $track->terrain );
        $lists['access']       = JHTML::_('select.genericlist', $users, 'access', 'size="2"', 'id', 'text', $track->access );

        $this->assignRef('editor',      $editor);
        $this->assignRef('lists',       $lists);
        $this->assignRef('track',       $track);
        $this->assignRef('id',          $id);

        parent::display($tpl);
    }
}
?>
